/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-11-24
 * Time: 23:45
 */
public class Solution {
    public boolean validPalindrome(String s) {
        int left = 0;
        int right = s.length()-1;
        boolean flag = true;
        while (left < right) {
            char start = s.charAt(left);
            char end = s.charAt(right);
            if (start == end) {
                left++;
                right--;
            }else {
                return isPalindrome(s,left+1,right) || isPalindrome(s,left,right-1);
            }
        }
        return true;
    }

    private boolean isPalindrome(String s,int left,int right) {
        while (left < right) {
            char start = s.charAt(left);
            char end = s.charAt(right);
            if (start != end) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
